<p id="f-0-1-introduction-md"></p>
<h1>About Go Optimizations 101</h1>

<p>This book offers practical tricks, tips, and suggestions to optimize Go code performance.
Its insights are grounded in the official Go compiler and runtime implementation.</p>

<p>Life is full of trade-offs, and so is the programming world.
In programming, we constantly balance trade-offs between code readability, maintainability, development efficiency, and performance, and even within each of these areas.
For example, optimizing for performance often involves trade-offs between memory savings, execution speed, and implementation complexity.</p>

<p>In real-world projects, most code sections don't demand peak performance.
Prioritizing maintainability and readability generally outweighs shaving every byte or microsecond.
This book focuses on optimizing critical sections where performance truly matters.
Be aware that some suggestions might lead to more verbose code or only exhibit significant gains in specific scenarios.</p>

<p>The contents in this book include:</p>

<ul>
<li>how to consume less CPU resources.</li>
<li>how to consume less memory.</li>
<li>how to make less memory allocations.</li>
<li>how to control memory allocation places.</li>
<li>how to reduce garbage collection pressure.</li>
</ul>

<p>This book neither explains how to use performance analysis tools, such as pprof,
nor tries to study deeply on compiler and runtime implementation details.
The books also doesn't introduce how to use <a href="https://go.dev/doc/pgo">profile-guided optimization</a>.
None of the contents provided in this book make use of unsafe pointers and cgo.
And the book doesn't talk about algorithms.
In other words, this book tries to provide some optimization suggestions
in a way which is clear and easy to understand, for daily general Go programming.</p>

<p>Without particularly indicated, the code examples provided in this book are tested and run on a notebook with the following environment setup:</p>

<pre><code>go version go1.24rc1 linux/amd64
goos: linux
goarch: amd64
cpu: Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
</code></pre>

<p>Some benchmark times information is removed from benchmark results, to keep benchmark lines short.</p>

<p>Please note that:</p>

<ul>
<li>some of the talked suggestions in this book work on any platform and for any CPU models, but some others might only work on specified platforms and for specified CPU models. So please benchmark them on the same environments as your production environments before adopting any of them.</li>
<li>some implementation details of the official standard Go compiler and runtime might change from version to version, which means some of the talked suggestions might not work for future Go toolchain versions.</li>
<li>the book will be open sourced eventually, in a chapter by chapter way.</li>
</ul>

<h2>About the author</h2>

<p>Tapir is the author of this book.
He also wrote the <a href="https://go101.org/article/101.html">Go 101</a> book.
He is planning to write some other <strong>Go 101</strong> series books.
Please look forward to.</p>

<p>Tapir was ever (maybe will be again) an indie game developer.
You can find his games here: <a href="https://tapirgames.com">tapirgames.com</a>.</p>

<h2>About GoTV</h2>

<p>During writing this book, the tool <a href="https://go101.org/apps-and-libs/gotv.html">GoTV</a>
is used to manage installations of multiple Go toolchain versions and check
the behavior differences between Go toolchain versions.</p>

<h2>Feedback</h2>

<p>Welcome to improve this book by submitting corrections to Go 101 issue list (<a href="https://github.com/go101/go101">https://github.com/go101/go101</a>) for all kinds of mistakes, such as typos, grammar errors, wording inaccuracies, wrong explanations, description flaws, code bugs, etc.</p>

<p>It is also welcome to send your feedback to the Go 101 twitter account: @zigo_101 (<a href="https://twitter.com/zigo_101">https://twitter.com/zigo_101</a>).</p>
